package wh.coach.utils;

import lombok.Getter;

public class ObjectWrapper<T> {

    private static final ObjectWrapper<?> UN_KNOWN = new ObjectWrapper<>(null, null);
    private static final ObjectWrapper<?> NOT_EXISTS = new ObjectWrapper<>(false, null);

    private final Boolean exists;
    @Getter
    private final T object;

    public ObjectWrapper(final Boolean exists, final T object) {
        this.exists = exists;
        this.object = object;
    }

    public static <T> ObjectWrapper<T> notExistsObject() {
        return (ObjectWrapper<T>) NOT_EXISTS;
    }

    public static <V> ObjectWrapper<V> of(final V object) {
        return new ObjectWrapper<>(true, object);
    }

    public static <T> ObjectWrapper<T> unknownObject() {
        return (ObjectWrapper<T>) UN_KNOWN;
    }

    public boolean exists() {
        return exists != null && exists;
    }

    public boolean existsUnknown() {
        return exists == null;
    }

    public boolean notExists() {
        return exists != null && !exists;
    }
}
